package com.ieng.ormosia.connect.service.impl;

import com.ieng.ormosia.connect.mapper.PermissionMapper;
import com.ieng.ormosia.connect.model.Permission;
import com.ieng.ormosia.connect.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class PermissionServiceImpl implements PermissionService {
	@Resource
	private PermissionMapper permissionMapper;

	@Override
	public List<Permission> getPermissionList() {
		return permissionMapper.selectAll();
	}

	@Override
	public List<Permission> getPermissionHashQ(Permission permission) {
		return permissionMapper.select(permission);
	}

	@Override
	public List<Permission> getPermissionDelAll() {
		return permissionMapper.selectDeletedList();
	}

	@Override
	public Permission getPermission(Long id) {
		return permissionMapper.selectByPrimaryKey(id);
	}

	@Transactional
	@Override
	public void addPermission(Permission permission) {
		permission.setCreateTime(LocalDateTime.now());
		permissionMapper.insert(permission);
	}

	@Transactional
	@Override
	public void editPermission(Permission permission) {
		permission.setChangeTime(LocalDateTime.now());
		permissionMapper.updateByPrimaryKey(permission);
	}

	@Transactional
	@Override
	public void removePermission(Long[] ids) {
		permissionMapper.updateDeletedByIds(ids);
	}

	@Transactional
	@Override
	public void delPermission(Long[] ids) {
		permissionMapper.deleteByIds(ids);
	}
}
